package main

import (
	"fmt"
	"os"
)

func main() {
	fp, err := os.OpenFile("cp6_file/write.txt", os.O_CREATE|os.O_RDWR, 0666)
	if err != nil {
		fmt.Println(err)
	}
	defer fp.Close()
	//通过文件指针可直接写文件，调用write方法，返回写入的字节数

	len, err := fp.Write([]byte{97, 98, 99}) //写abc
	fmt.Println(len, err)
	len, err = fp.WriteAt([]byte{100}, 0) //在off位置写d
	fmt.Println(len, err)
	len, err = fp.WriteString("我的") //写字符串
	fmt.Println(len, err)
}
